package ua.maxicash.util.criteria.handlers;

import org.hibernate.criterion.*;
import ua.maxicash.util.Filter;
import ua.maxicash.util.criteria.RestrictionsWrapper;
import ua.maxicash.vo.City;

import java.util.List;

public class CityCriteriaHandler extends CriteriaHandler {

	private Filter filter;

    public CityCriteriaHandler() {
    }

    public CityCriteriaHandler(List<String> aliases) {
        super(aliases);
    }

    @Override
	public void setUp(Filter filter) {
		this.filter = filter;
	}

	@Override
	public DetachedCriteria handle(DetachedCriteria criteria, Junction junction) {

//        criteria.createCriteria("city").add(junction.add(Restrictions.or(RestrictionsWrapper.getCriterion(
//				filter.getOp(), "ruName", filter.getData()),
//				RestrictionsWrapper.getCriterion(filter.getOp(),
//						"enName", filter.getData()))));
        if (!aliases.contains("city")) {
            criteria.createAlias("city","city");
            aliases.add("city");
        }
        junction.add(Restrictions.or(RestrictionsWrapper.getCriterion(
				filter.getOp(), "city.ruName", filter.getData()),
				RestrictionsWrapper.getCriterion(filter.getOp(),
						"city.enName", filter.getData())));


		return criteria;
	}
}
